
from django.template import Library
from django.urls import reverse
from web import models
register = Library()
@register.inclusion_tag('inclusion/all_project_list.html')
def all_project_list(request):
    # 0.先要获取当前用户request,从调用all_project_list引入
    # 1.获取我创建的所有项目
    my_project_list=models.Project.objects.filter(creator=request.tracer.user)
    # 2.获取我参与的所有项目
    join_project_list=models.ProjectUser.objects.filter(user=request.tracer.user)
    return{'my':my_project_list,'join':join_project_list,'request':request}

@register.inclusion_tag('inclusion/manage_menu_list.html')
def manage_menu_list(request):
    data_list=[
        {'title':'概览','url':reverse('web:dashboard',kwargs={'project_id':request.tracer.project.id})},
        {'title':'问题','url':reverse('web:issues',kwargs={'project_id':request.tracer.project.id})},
        {'title':'数据','url':reverse('web:statistics',kwargs={'project_id':request.tracer.project.id})},
        {'title':'wiki','url':reverse('web:wiki',kwargs={'project_id':request.tracer.project.id})},
        {'title':'文件','url':reverse('web:file',kwargs={'project_id':request.tracer.project.id})},
        {'title':'配置','url':reverse('web:setting',kwargs={'project_id':request.tracer.project.id})},
    ]
    # 默认菜单选中
    for item in data_list:
        if request.path_info.startswith(item['url']):
            item['class']='active'

    return {'data_list':data_list}